import { reqHomeDB } from '../api';
//home模块的小仓库
const state = {
    //state中数据默认初始值不能乱写，服务器返回对象/数组，需要根据接口返回值初始化
    homeDB: {
        channelList:[]
    },//首页数据,
    brandList:[]
    
};
// 
const actions = { 
    //通过API里面的接口函数调用，向服务器发送请求，获取服务器的数据
    async getHomeDB({commit}){//同步
        let result = await reqHomeDB();//等待请求获取结果     
        console.log(11111111,result);   
        commit("GETHOMEDB",result);
    },
};
// 
const mutations = {
    GETHOMEDB(state,result){
        state.homeDB = result;

    },
};
// 
const getters = {
 //宫格
 channel(state){
    return state.homeDB.channel;
},
//品牌制造商
brandList(state){
    return state.homeDB.brandList;
},
//新品首发
newGoodsList(state){
    return state.homeDB.newGoodsList;
},
//人气推荐
hotGoodsList(state){
    return state.homeDB.hotGoodsList;
},
//专题精选
topicList(state){
    return state.homeDB.topicList;
},
//商品
categoryList(state){
    return state.homeDB.categoryList;
},

currentCategory(state){
    return state.homeDB.currentCategory;
},

// 专题页
topicIndexList(state){
    return state.homeDB.topicIndexList;
},
//分类页
channelList(state){
    return state.homeDB.channelList;
},
}



export default {
    state,
    actions,
    mutations, 
    getters
}